﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;

namespace Website
{
    public class GlobalApplication : System.Web.HttpApplication
    {
        public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

            routes.MapRoute(
                "DELETE page/{title}",
                "page/{title}",
                new { controller = "Page", action = "Delete", id = (string)null },
                new { httpMethod = new HttpMethodConstraint("DELETE") }
            );

            routes.MapRoute(
                "POST page",
                "page",
                new { controller = "Page", action = "Post", id = (string)null },
                new { httpMethod = new HttpMethodConstraint("POST") }
            );

            routes.MapRoute(
                "PUT page/{title}",
                "page/{title}",
                new { controller = "Page", action = "Put", id = (string)null },
                new { httpMethod = new HttpMethodConstraint("PUT") }
            );

            routes.MapRoute(
                "page/{title}.atom",
                "page/{title}.atom",
                new { controller = "Page", action = "AtomRepresentation", id = (string)null }
            );

            routes.MapRoute(
                "page/{title}.html",
                "page/{title}.html",
                new { controller = "Page", action = "HtmlRepresentation", id = (string)null }
            );

            routes.MapRoute(
                "page/{title}.txt",
                "page/{title}.txt",
                new { controller = "Page", action = "TextRepresentation", id = (string)null }
            );

            routes.MapRoute(
                "page/{title}",
                "page/{title}",
                new { controller = "Page", action = "ContentNegotiation", id = (string)null }
            );

            routes.MapRoute(
                "Default",                                              // Route name
                "{controller}/{action}/{id}",                           // URL with parameters
                new { controller = "Home", action = "Index", id = "" }  // Parameter defaults
            );
        }

        protected void Application_Start()
        {
            RegisterRoutes(RouteTable.Routes);
        }
    }
}